package com.zjyd.douyangcommonquartz.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class QuartzConfig {

    // 执行器名称
    @Value("${spring.job.executor.name}")
    private String appname;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        // 执行器配置
        String adminAddresses = "http://192.168.0.151:8004/xxl-job-admin";
        // 执行器地址
        String ip = "";
        // 执行器端口
        int port = -1;
        // 执行器注册的Token
        String accessToken = "default_token";
        //  日志路径 获取当前项目路径
        String logPath = System.getProperty("user.dir") + "/logs";
        // 日志保留天数
        int logRetentionDays = 7;

        log.info(">>>>>>>>>>> xxl-job config init finish.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appname);
        xxlJobSpringExecutor.setIp(ip);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
        return xxlJobSpringExecutor;
    }
}
